package cn.sccdlg.spring5.service.impl;

import cn.sccdlg.spring5.dao.AccountDao;
import cn.sccdlg.spring5.factory.BeanFactory;
import cn.sccdlg.spring5.service.AccountService;

/**
 * @author RaoShuang
 * @emil 991207823@qq.com
 * @date 2020/11/2 09:16
 * 账户的业务层实现类
 */
public class AccountServiceImpl implements AccountService {
    /**
     * 早期业务层和持久化层高耦合示例
     */
    /** private AccountDao accountDao = new AccountDaoImpl();*/

    /**
     * 工厂模式解耦，并且针对不在改变的对象，优先保证只有一份
     */
    AccountDao accountDao = (AccountDao) BeanFactory.getBean("accountDao");
    /** 对于需要保证数据不被修改，应当定义在方法内部，而不是类成员*/
    private int i = 1;

    @Override
    public void saveAccount() {
        int i = 1;
        System.out.println(accountDao);
        accountDao.saveAccount();
        System.out.println(i);
        i++;
    }
}
